﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Text.RegularExpressions;

namespace 第三次作业
{
    internal class formatting
    {
        public void format(string source)
        {
            FileStream fs = new FileStream(source, FileMode.Open,FileAccess.Read);
            StreamReader sr = new StreamReader(fs,System.Text.Encoding.UTF8);
            string? line;
            string tempSource = Path.GetTempFileName();
            FileStream fs2 = new FileStream(tempSource, FileMode.Create,FileAccess.Write);
            StreamWriter sw = new StreamWriter(fs2,System.Text.Encoding.UTF8);

            for (string s = sr.ReadLine(); s != null; s = sr.ReadLine())
            {
                if (Regex.IsMatch(s, @"^\s*$"))
                {
                    //什么都不做
                    continue;
                }
                if (Regex.IsMatch(s, @"^\s*//.*$"))
                {
                    //什么都不做
                    continue ;
                }
                sw.WriteLine(s);
            }
            sr.Close();
            sw.Close();
            File.Move(tempSource, source,true);

        }
    }
}
